package com.caltco.cargo.ops.modules.sys.controller;

import com.caltco.cargo.ops.common.api.R2;
import com.caltco.cargo.ops.common.api.Result;
import com.caltco.cargo.ops.common.base.gen.BaseController;
import com.caltco.cargo.ops.modules.sys.entity.Project;
import com.caltco.cargo.ops.modules.sys.entity.SysUserEntity;
import com.caltco.cargo.ops.modules.sys.request.ProjectRequest;
import com.caltco.cargo.ops.modules.sys.service.ProjectService;
import com.caltco.cargo.ops.modules.sys.vo.ProjectVO;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController("projectController")
@RequestMapping("/api/project")
public class ProjectController extends BaseController<Project,ProjectService> {

    private final ProjectService projectService;

    public ProjectController(ProjectService projectService) {
        this.projectService = projectService;
    }

    @GetMapping("top")
    @Operation(summary = "置顶")
    public Result<String> top(@RequestParam("id") Long id, @RequestParam("isTop") Integer isTop) {
        return projectService.top(id, isTop) ? R2.setOkMsg("置顶成功"):R2.setErrMsg(("置顶失败"));
    }

    @GetMapping("collection")
    @Operation(summary = "收藏")
    public Result<String> collection(@RequestParam("id") Long id, @RequestParam("isCollection") Integer isCollection) {
        return projectService.collection(id, isCollection) ? R2.setOkMsg("收藏成功"):R2.setErrMsg(("收藏失败"));
    }

    @PostMapping("save")
    @Operation(summary = "新增项目")
    public Result<String> save(@RequestBody ProjectRequest projectRequest) {
        return projectService.save(projectRequest) ? R2.setOkMsg("新增成功"):R2.setErrMsg(("新增失败"));
    }

    @PutMapping("update")
    @Operation(summary = "修改项目")
    public Result<String> update(@RequestBody ProjectRequest projectRequest) {
        return projectService.update(projectRequest) ? R2.setOkMsg("修改成功"):R2.setErrMsg(("修改失败"));
    }

    @PostMapping("join")
    @Operation(summary = "加入项目")
    public Result<String> join(@RequestBody ProjectRequest projectRequest) {
        return projectService.join(projectRequest) ? R2.setOkMsg("加入成功"):R2.setErrMsg(("加入失败"));
    }

    @PostMapping("get")
    @Operation(summary = "查找项目")
    public Result<List<ProjectVO>> get(@RequestBody ProjectRequest projectRequest) {
        return R2.ok(projectService.get(projectRequest));
    }

    @PostMapping("getCreate")
    @Operation(summary = "查找自己创建的项目")
    public Result<List<ProjectVO>> getCreate(@RequestBody ProjectRequest projectRequest) {
        return R2.ok(projectService.getCreate(projectRequest));
    }

    @PostMapping("getJoin")
    @Operation(summary = "查找自己参见的项目")
    public Result<List<ProjectVO>> getJoin(@RequestBody ProjectRequest projectRequest) {
        return R2.ok(projectService.getJoin(projectRequest));
    }

    @GetMapping("getPersonList")
    @Operation(summary = "查找项目组的人数")
    public Result<List<SysUserEntity>> getPersonList(Long id) {
        return R2.ok(projectService.getPersonList(id));
    }

    @DeleteMapping("remove/{id}")
    @Operation(summary = "删除项目")
    public Result<String> remove(@PathVariable("id") Long id) {
        return projectService.remove(id) ? R2.setOkMsg("删除成功"):R2.setErrMsg(("删除失败"));
    }

}
